﻿using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Data;
using System.Data.SqlClient;
using gcLibAdmin;

/// <summary>
/// Summary description for WS_Tho_NguyenLieu
/// </summary>

[WebService(Namespace = "http://www.anhxuan.com.vn/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WS_Tho_NguyenLieu : System.Web.Services.WebService
{

    public WS_Tho_NguyenLieu()
    {

    }

    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }
    /// <summary>
    /// Thêm mới Nguyên liệu, gia mua
    /// vao bảng Nguyen lieu hang ngay
    /// </summary>
    /// <param name="NguyenLieuId">Nguyen lieu</param>
    /// <param name="GiaMua"></param>
    /// <param name="type">Loai cap nhat hay
    /// type = 1 : lúc này danh muc nguyen lieu duoc them moi
    /// type = 2 : lúc này danh mục nguyen lieu duoc update
    /// </param>
    [WebMethod]
    [ScriptMethod]
    public static void Insert_NguyenLieu_HangNgay(int type, string NguyenLieuId, string GiaMua)
    {
        int intNguyenLieuId = int.Parse(NguyenLieuId);
        double douGiaMua = double.Parse(GiaMua);
        string cnnString = Helper.getOleStr();
        SqlConnection cnn = new SqlConnection(cnnString);
        SqlCommand cmd;
        try
        {
            cnn.Open();
            cmd = new SqlCommand("proc_Tho_InsertNguyenLieuGiaTheoNgay", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Loai", SqlDbType.Int);
            cmd.Parameters["@Loai"].Value = type;
            cmd.Parameters.Add("@NguyenLieuId", SqlDbType.Int);
            cmd.Parameters["@NguyenLieuId"].Value = intNguyenLieuId;
            cmd.Parameters.Add("@GiaMua", SqlDbType.Float);
            cmd.Parameters["@GiaMua"].Value = douGiaMua;
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            string msg = ex.Message.ToString();
        }
        finally
        {
            cnn.Close();
        }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="type"></param>
    /// <param name="NguyenLieuId"></param>
    /// <param name="GiaMua"></param>
    [WebMethod]
    [ScriptMethod]
    public static void Update_ChiPhiMonAn(int NguyenLieuId, double GiaMua)
    {
        string cnnString = Helper.getOleStr();
        SqlConnection cnn = new SqlConnection(cnnString);
        SqlCommand cmd;
        try
        {
            cnn.Open();
            cmd = new SqlCommand("proc_Tho_UpdateMonAnChiTiet", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@NguyenLieuId", SqlDbType.Int);
            cmd.Parameters["@NguyenLieuId"].Value = NguyenLieuId;
            cmd.Parameters.Add("@GiaMua", SqlDbType.Float);
            cmd.Parameters["@GiaMua"].Value = GiaMua;
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            string msg = ex.Message.ToString();
        }
        finally
        {
            cnn.Close();
        }
    }
}

